﻿/*
==================================================================
    注意：此文件为Auto代码，不可手动修改【单据】
==================================================================
*/

namespace Services
{
    /// <summary>
    /// Auto单据
    /// </summary>
    public abstract class AutoBillMapping : BaseMapping<Bill, BillModel, BillFilterModel>
    {
        public AutoBillMapping(ICurrentUser currentUser)
            : base(currentUser) { }

        #region 读数据
        /// <summary>
        /// 读数据，从Entity对象转成Model对象
        /// </summary>
        /// <param name="entity">Entity对象</param>
        /// <returns></returns>
        public override BillModel Entity2Model(Bill entity)
        {
            BillModel model = new BillModel();

            model.BillID = entity.BillID;
            model.GroupInfoID = entity.GroupInfoID;
            model.Code = entity.Code;
            model.BillDate = entity.BillDate;
            model.InOutType = entity.InOutType;
            model.OperTypeID = entity.OperTypeID;
            model.WarehouseID = entity.WarehouseID;
            model.ApplyUserID = entity.ApplyUserID;
            model.ApplyUserName = entity.ApplyUserName;
            model.SubmitUserID = entity.SubmitUserID;
            model.SubmitUserName = entity.SubmitUserName;
            model.SubmitDate = entity.SubmitDate;
            model.BackUserID = entity.BackUserID;
            model.BackUserName = entity.BackUserName;
            model.BackDate = entity.BackDate;
            model.ConfirmUserID = entity.ConfirmUserID;
            model.ConfirmUserName = entity.ConfirmUserName;
            model.ConfirmDate = entity.ConfirmDate;
            model.Status = entity.Status;
            model.BackReason = entity.BackReason;
            model.Remark = entity.Remark;
            model.CreateUserID = entity.CreateUserID;
            model.CreateUserName = entity.CreateUserName;
            model.CreateDate = entity.CreateDate;

            return model;
        }
        #endregion

        #region 写数据
        /// <summary>
        /// 写数据，从Model对象转换成Entity对象
        /// </summary>
        /// <param name="model">ViewModel对象</param>
        /// <returns></returns>
        public override Bill Model2Entity(BillModel model)
        {
            Bill entity = new Bill();

            entity.BillID = model.BillID;
            entity.GroupInfoID = model.GroupInfoID;
            entity.Code = model.Code;
            entity.BillDate = model.BillDate;
            entity.InOutType = model.InOutType;
            entity.OperTypeID = model.OperTypeID;
            entity.WarehouseID = model.WarehouseID;
            entity.ApplyUserID = model.ApplyUserID;
            entity.ApplyUserName = model.ApplyUserName;
            entity.SubmitUserID = model.SubmitUserID;
            entity.SubmitUserName = model.SubmitUserName;
            entity.SubmitDate = model.SubmitDate;
            entity.BackUserID = model.BackUserID;
            entity.BackUserName = model.BackUserName;
            entity.BackDate = model.BackDate;
            entity.ConfirmUserID = model.ConfirmUserID;
            entity.ConfirmUserName = model.ConfirmUserName;
            entity.ConfirmDate = model.ConfirmDate;
            entity.Status = model.Status;
            entity.BackReason = model.BackReason;
            entity.Remark = model.Remark;
            entity.CreateUserID = model.CreateUserID;
            entity.CreateUserName = model.CreateUserName;
            entity.CreateDate = model.CreateDate;

            return entity;
        }
        #endregion

        #region 搜索条件转换
        /// <summary>
        /// 搜索条件转换，从FilterModel对象转换成Where对象
        /// </summary>
        /// <param name="filterModel">FilterModel对象</param>
        /// <returns></returns>
        public override Expressionable<Bill> FilterModel2Where(BillFilterModel filterModel)
        {
            var where = base.FilterModel2Where(filterModel);

            //编号
            if (filterModel._BillID.HasValue)
            {
                where = where.And(x => x.BillID == filterModel._BillID.Value);
            }
            if (filterModel._BillIDs.IsNotEmpty() && filterModel._BillIDs.Count > 0)
            {
                where = where.And(x => filterModel._BillIDs.Contains(x.BillID));
            }
            if (filterModel._NotBillIDs.IsNotEmpty() && filterModel._NotBillIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotBillIDs.Contains(x.BillID));
            }

            //集团
            if (filterModel._GroupInfoID.HasValue)
            {
                where = where.And(x => x.GroupInfoID == filterModel._GroupInfoID.Value);
            }
            if (filterModel._GroupInfoIDs.IsNotEmpty() && filterModel._GroupInfoIDs.Count > 0)
            {
                where = where.And(x => filterModel._GroupInfoIDs.Contains(x.GroupInfoID));
            }
            if (filterModel._NotGroupInfoIDs.IsNotEmpty() && filterModel._NotGroupInfoIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotGroupInfoIDs.Contains(x.GroupInfoID));
            }

            //单号
            if (!string.IsNullOrEmpty(filterModel._Code))
            {
                where = where.And(x => x.Code.Contains(filterModel._Code));
            }
            if (!string.IsNullOrEmpty(filterModel._CodeEqual))
            {
                where = where.And(x => x.Code == filterModel._CodeEqual);
            }

            //日期
            if (filterModel._BillDate.HasValue)
            {
                where = where.And(x => x.BillDate == filterModel._BillDate.Value);
            }
            if (filterModel._BillDate_Begin.HasValue)
            {
                where = where.And(x => x.BillDate >= filterModel._BillDate_Begin.Value);
            }
            if (filterModel._BillDate_End.HasValue)
            {
                where = where.And(x => x.BillDate < filterModel._BillDate_End.Value.AddDays(1));
            }

            //类型
            if (filterModel._InOutType.HasValue)
            {
                where = where.And(x => x.InOutType == filterModel._InOutType.Value);
            }
            if (filterModel._InOutTypes.IsNotEmpty() && filterModel._InOutTypes.Count > 0)
            {
                where = where.And(x => filterModel._InOutTypes.Contains(x.InOutType));
            }
            if (filterModel._NotInOutTypes.IsNotEmpty() && filterModel._NotInOutTypes.Count > 0)
            {
                where = where.And(x => !filterModel._NotInOutTypes.Contains(x.InOutType));
            }

            //业务类型
            if (filterModel._OperTypeID.HasValue)
            {
                where = where.And(x => x.OperTypeID == filterModel._OperTypeID.Value);
            }
            if (filterModel._OperTypeIDs.IsNotEmpty() && filterModel._OperTypeIDs.Count > 0)
            {
                where = where.And(x => filterModel._OperTypeIDs.Contains(x.OperTypeID));
            }
            if (filterModel._NotOperTypeIDs.IsNotEmpty() && filterModel._NotOperTypeIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotOperTypeIDs.Contains(x.OperTypeID));
            }

            //仓库
            if (filterModel._WarehouseID.HasValue)
            {
                where = where.And(x => x.WarehouseID == filterModel._WarehouseID.Value);
            }
            if (filterModel._WarehouseIDs.IsNotEmpty() && filterModel._WarehouseIDs.Count > 0)
            {
                where = where.And(x => filterModel._WarehouseIDs.Contains(x.WarehouseID));
            }
            if (filterModel._NotWarehouseIDs.IsNotEmpty() && filterModel._NotWarehouseIDs.Count > 0)
            {
                where = where.And(x => !filterModel._NotWarehouseIDs.Contains(x.WarehouseID));
            }

            //申请人姓名
            if (!string.IsNullOrEmpty(filterModel._ApplyUserName))
            {
                where = where.And(x => x.ApplyUserName.Contains(filterModel._ApplyUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._ApplyUserNameEqual))
            {
                where = where.And(x => x.ApplyUserName == filterModel._ApplyUserNameEqual);
            }

            //提交人姓名
            if (!string.IsNullOrEmpty(filterModel._SubmitUserName))
            {
                where = where.And(x => x.SubmitUserName.Contains(filterModel._SubmitUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._SubmitUserNameEqual))
            {
                where = where.And(x => x.SubmitUserName == filterModel._SubmitUserNameEqual);
            }

            //提交时间
            if (filterModel._SubmitDate.HasValue)
            {
                where = where.And(x => x.SubmitDate == filterModel._SubmitDate.Value);
            }
            if (filterModel._SubmitDate_Begin.HasValue)
            {
                where = where.And(x => x.SubmitDate >= filterModel._SubmitDate_Begin.Value);
            }
            if (filterModel._SubmitDate_End.HasValue)
            {
                where = where.And(x => x.SubmitDate < filterModel._SubmitDate_End.Value.AddDays(1));
            }

            //退回/作废人姓名
            if (!string.IsNullOrEmpty(filterModel._BackUserName))
            {
                where = where.And(x => x.BackUserName.Contains(filterModel._BackUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._BackUserNameEqual))
            {
                where = where.And(x => x.BackUserName == filterModel._BackUserNameEqual);
            }

            //退回/作废时间
            if (filterModel._BackDate.HasValue)
            {
                where = where.And(x => x.BackDate == filterModel._BackDate.Value);
            }
            if (filterModel._BackDate_Begin.HasValue)
            {
                where = where.And(x => x.BackDate >= filterModel._BackDate_Begin.Value);
            }
            if (filterModel._BackDate_End.HasValue)
            {
                where = where.And(x => x.BackDate < filterModel._BackDate_End.Value.AddDays(1));
            }

            //确认人姓名
            if (!string.IsNullOrEmpty(filterModel._ConfirmUserName))
            {
                where = where.And(x => x.ConfirmUserName.Contains(filterModel._ConfirmUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._ConfirmUserNameEqual))
            {
                where = where.And(x => x.ConfirmUserName == filterModel._ConfirmUserNameEqual);
            }

            //确认时间
            if (filterModel._ConfirmDate.HasValue)
            {
                where = where.And(x => x.ConfirmDate == filterModel._ConfirmDate.Value);
            }
            if (filterModel._ConfirmDate_Begin.HasValue)
            {
                where = where.And(x => x.ConfirmDate >= filterModel._ConfirmDate_Begin.Value);
            }
            if (filterModel._ConfirmDate_End.HasValue)
            {
                where = where.And(x => x.ConfirmDate < filterModel._ConfirmDate_End.Value.AddDays(1));
            }

            //状态
            if (filterModel._Status.HasValue)
            {
                where = where.And(x => x.Status == filterModel._Status.Value);
            }
            if (filterModel._Statuss.IsNotEmpty() && filterModel._Statuss.Count > 0)
            {
                where = where.And(x => filterModel._Statuss.Contains(x.Status));
            }
            if (filterModel._NotStatuss.IsNotEmpty() && filterModel._NotStatuss.Count > 0)
            {
                where = where.And(x => !filterModel._NotStatuss.Contains(x.Status));
            }

            //创建人姓名
            if (!string.IsNullOrEmpty(filterModel._CreateUserName))
            {
                where = where.And(x => x.CreateUserName.Contains(filterModel._CreateUserName));
            }
            if (!string.IsNullOrEmpty(filterModel._CreateUserNameEqual))
            {
                where = where.And(x => x.CreateUserName == filterModel._CreateUserNameEqual);
            }

            //创建日期
            if (filterModel._CreateDate.HasValue)
            {
                where = where.And(x => x.CreateDate == filterModel._CreateDate.Value);
            }
            if (filterModel._CreateDate_Begin.HasValue)
            {
                where = where.And(x => x.CreateDate >= filterModel._CreateDate_Begin.Value);
            }
            if (filterModel._CreateDate_End.HasValue)
            {
                where = where.And(x => x.CreateDate < filterModel._CreateDate_End.Value.AddDays(1));
            }

            return where;
        }
        #endregion
    }
}

